<template>
  <div class="common_wrap">
    <div class="common_title">指标信息维护</div>
    <el-form ref="queryForm" :model="queryParams" label-width="75px" inline class="search-nav">
        <el-form-item prop="indicator" label="指标名称">
          <el-input v-model="queryParams.indicator" maxlength="20" placeholder="请输入指标名称" clearable />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">查询</el-button>
          <el-button type="primary" plain icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    <div class="btn-container" style="text-align: right">
      <el-button type="primary" icon="el-icon-upload2">导入</el-button>
      <el-button type="primary" icon="el-icon-plus" @click="toAdd">新建</el-button>
    </div>
    <el-table ref="table" v-loading="tableLoading" :data="tableData">
      <el-table-column prop="quotaId" label="指标ID" align="center" width="120px" />
      <el-table-column prop="quotaName" label="指标名称" align="center" />
      <el-table-column prop="dimensionList" label="指标维度" align="center">
        <template slot-scope="scope">
          <span v-for="item in scope.row.dimensionList" :key="item.index">{{ item.dimension+'('+item.unit+')' }}   </span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="100px">
        <template slot-scope="scope">
          <el-tooltip content="编辑" placement="top">
            <el-button type="primary" icon="el-icon-edit" circle @click="handleClaim(scope.row)" />
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        class="pagination-container"
        :background="true"
        :current-page="queryParams.current"
        :page-sizes="[10, 20, 30, 40, 50]"
        :page-size="queryParams.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="sizeChange"
        @current-change="currentChange"
    />
  </div>
</template>

<script>
export default {
  name: "InfoMaintain",
  data() {
    return {
      // 搜索条件
      queryParams: {
        indicator: '',
        current: 1, // 第几页
        size: 10 // 每页条数
      },
      total: 0, // 总条数
      tableLoading: false, // 表格loading
      tableData: [], // 表格数据
    }
  },
  created(){
    this.getTableData()
  },
  methods: {
    resetQuery() {
      this.queryParams = {
        indicator:'',
        current: 1,
        size: 10
      }
      this.getTableData()
    },
    handleQuery() {
      this.queryParams.current = 1
      this.getTableData()
    },
    // 每页显示数量变化
    sizeChange(size) {
      this.queryParams.size = size
      this.queryParams.current = 1
      this.getTableData()
    },

    // 当前页变化
    currentChange(current) {
      this.queryParams.current = current
      this.getTableData()
    },
    getTableData(){
      this.tableLoading = true
      const params = {
        quotaName: this.queryParams.indicator,
        page: this.queryParams.current,
        limit: this.queryParams.size
      }
      this.$api.quotaList(params).then(res=>{
        this.tableLoading = false
        if(res.status === 200){
          this.tableData = res.data.items
          this.total = res.data.count
        }else{
          this.tableData = []
          this.total = 0
        }
      })
    },
    toAdd() {
      this.$router.push({path: '/infoMaintain/edit'})
    },
    handleClaim(item){
      this.$router.push({
        path: '/infoMaintain/edit',
        query:{
          ...item
        }
      })
    }
  }
}
</script>

<style scoped>

</style>